<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<!-- 모바일 웹 페이지 설정 -->
<link rel="shortcut icon" href="assets/ico/favicon.png" />
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png" />

<!-- bootstrap -->
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css" />
<!-- 나눔고딕 웹 폰트 적용 -->
<link rel="stylesheet" type="text/css" href="assets/css/nanumfont.css" />

<link rel="stylesheet" type="text/css" href="assets/font-awesome-4.0.3/css/font-awesome.min.css" />

<!-- 반응형 웹을 지원하지 않을 경우 -->
<!-- <link rel="stylesheet" href="assets/css/non-responsive.css" /> -->

<!-- IE8 이하 버전 지원 -->
<!--[if lt IE 9]>
	<script type="text/javascript" src="assets/js/html5shiv.js"></script>
	<script type="text/javascript" src="assets/js/respond.min.js"></script>
<![endif]-->
<!-- IE10 반응형 웹 버그 보완 -->
<!--[if gt IE 9]>
	<link rel="stylesheet" type="text/css" href="assets/css/ie10.css" />
	<script type="text/javascript" src="assets/js/ie10.js"></script>
<![endif]-->

<title>경로검색 결과</title>

<link rel="stylesheet" href="assets/css/select_result.css">

</head>

<body>
	<input type="hidden" id="start" value="">
	<input type="hidden" id="end" value="">
	<input type="hidden" id="hh" value="">
	<input type="hidden" id="mm" value="">

	<!-- 상단 해더 바 -->
	<nav class="navbar navbar-fixed-top" role="navigation">
		<div class="nav_content text-center">
			<div class="nav_menu_btn pull-left text-center">
				<a class="back_btn" onclick="history.back();"><i class="fa fa-arrow-left"></i></a>
			</div>
			<span class="page_title"><strong>경로선택</strong></span>
		</div>
	</nav>
	<!-- 상단 해더 끝 -->
	
	<div id="test" class="panel-group">
	</div>
	
	
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>	
	<script	src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
	<script src="assets/js/googlemap.js"></script>
	<script src="assets/js/jquery.xml2json.js"></script>
	<script type="text/javascript">
		var smapx = '';
		var smapy = '';
		var emapx = '';
		var empay = '';
	
		$(function() {
			if (sessionStorage["sg"] == '') {
				var naver_url = "http://openapi.naver.com/search?key=83094044549bcd85ea2214d754f913f1&query=" + encodeURI(sessionStorage["sl"]) + "&target=local&start=1&display=1";
				$.ajax({
					url : "proxy.jsp",
					data : {"url" : naver_url},
					dataType : "xml",
					timeout : 30000,
					cache : false,
					success : function(req) {
						var json = $.xml2json(req);
						
						smapx = json.channel.item.mapx;
						smapy = json.channel.item.mapy;
						
						sgps();
					},
					error : function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			} else if (sessionStorage["sg"] != '') {
				$('#start').val(sessionStorage["sg"]);
				load();
			}
			
			if (sessionStorage["eg"] == '') {
				var naver_url = "http://openapi.naver.com/search?key=83094044549bcd85ea2214d754f913f1&query=" + encodeURI(sessionStorage["el"]) + "&target=local&start=1&display=1";
				
				$.ajax({
					url : "proxy.jsp",
					data : {"url" : naver_url},
					dataType : "xml",
					timeout : 30000,
					cache : false,
					success : function(req) {
						var json = $.xml2json(req);
						
						emapx = json.channel.item.mapx;
						emapy = json.channel.item.mapy;
						
						egps();
					},
					error : function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			} else if (sessionStorage["eg"] != '') {
				$('#end').val(sessionStorage["eg"]);
				load();
			}
		});
		
		function load() {
			var st = $('#start').val().split(",");
			var ed = $('#end').val().split(",");
			if (st.length == 2) {
				if (ed.length == 2) {
					calcRoute();
				}	
			}
		}
		
		function sgps() {
			if (smapx != '') {
				$.ajax({
					url : "http://apis.daum.net/local/geo/transcoord",
					dataType : "jsonp",
					data : {
						"apikey" : "0742d1ea1eab6220018c3f9716569897d5ec4ff5",
						"x" : smapx,
						"y" : smapy,
						"fromCoord" : "KTM",
						"toCoord" : "WGS84",
						"output" : "json"
					},
					timeout : 30000,
					cache : false,
					success : function(req) {
						$('#start').val(req.y + ',' + req.x);
						sessionStorage["sg"] = req.y + ',' + req.x;
						load();
					},
					error : function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
		}
		
		function egps() {
			if (emapx != '') {
				$.ajax({
					url : "http://apis.daum.net/local/geo/transcoord",
					dataType : "jsonp",
					data : {
						"apikey" : "0742d1ea1eab6220018c3f9716569897d5ec4ff5",
						"x" : emapx,
						"y" : emapy,
						"fromCoord" : "KTM",
						"toCoord" : "WGS84",
						"output" : "json"
					},
					timeout : 30000,
					cache : false,
					success : function(req) {
						$('#end').val(req.y + ',' + req.x);
						sessionStorage["eg"] = req.y + ',' + req.x;
						load();
					},
					error : function(xhr, status, error) {
						alert("status: " + status + " / error-code: " + xhr.status + " " + error);
					}
				});
			}
		}
	</script>
</body>
</html>

